package kr.nexmore.slmsample2.view.chartsample;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;

import javax.annotation.PostConstruct;

import org.eclipse.birt.report.engine.emitter.html.URLEncoder;
import org.eclipse.birt.report.viewer.utilities.WebViewer;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.osgi.framework.Bundle;

public class ChartPart {

	public static final String ID = "de.vogella.birt.stocks.rcp.view";

	private Text name_txt;
	private Text add_txt;
	private Text phone_txt;
	private Table table;

	public ChartPart() {
	}

	/**
	 * Create contents of the view part.
	 */
	@PostConstruct
	public void createControls(Composite parent) {
		String path = "";
		try {
			Bundle bundle = Platform.getBundle("kr.nexmore.slmsample2");
			URL url = FileLocator
					.find(bundle,
							new Path(
									"/src/kr/nexmore/slmsample2/report/stock_report.rptdesign"),
							null);
			path = FileLocator.toFileURL(url).getPath();
		} catch (MalformedURLException me) {
			System.out.println("Fehler bei URL " + me.getStackTrace());
		} catch (IOException e) {
			e.printStackTrace();
		}

		Browser browser = new Browser(parent, SWT.NONE);

		// use the filename of your report
		// WebViewer.display(path, WebViewer.HTML, browser, "frameset");

		HashMap myparms = new HashMap();
		HashMap emitmap = new HashMap();

		myparms.put("SERVLET_NAME_KEY", "frameset");
		myparms.put("FORMAT_KEY", "html");
		// myparms.put("RESOURCE_FOLDER_KEY", "c:/myresources");
		myparms.put("ALLOW_PAGE", "false");
		myparms.put("SHOW_PARAMETER_PAGE", "false");
		// myparms.put(WebViewer.MAX_ROWS_KEY, "5");

		emitmap.put("addtorul", URLEncoder.encode("addtourl", "UTF-8"));
		myparms.put("EMITTER_OPTIONS_KEY", emitmap);
		// myparms.put("MAX_ROWS_KEY", "500");
		WebViewer.display(path, browser, myparms);

		// WebViewer.display(reportName, myparms);

	}

}
